<template>
  <div>
    <TopFilter :list="topFilterList" :cols="4" @filterChange="changeHandler" @onCollapse="collapseHandle" />
    <FilterTable
      ref="table"
      columnsRef="partInventoryManagerPartOpeningInventoryMaintenanceIndex"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSelectColumn="false"
      :onRowSelectChange="rowSelectHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="moreActions">
        <!-- <span @click="removeRecordHandle">删除数据</span> -->
      </template>
      <template slot="controls">
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="addRecordHandle">新建</el-button>

        <el-button size="small" icon="el-icon-printer">打印</el-button>-->
      </template>
    </FilterTable>
  </div>
</template>

<script>
// 数据字典/按钮权限
import { dictionary } from '@/utils/dictMixin';
import { getPartOpeningInventoryDatas } from '@/api/part/inventoryManager/partOpeningInventoryMaintenance';
import { getStroageList } from '@/api/part/partOutbound/partBreak';

export default {
  name: 'CardType',
  components: {},
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    this.selectedRow = null;
    this.editData = {};
    return {
      topFilterList: this.createTopFilters(),
      columns: this.createTableColumns(),
      fetchApi: getPartOpeningInventoryDatas,
      fetchParams: {},
      actions: { visible: false, type: '', title: '' } // 弹出面板的相关信息
    };
  },
  created() {
    this.getStorage();
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'STORAGE_CODE',
          initialValue: '',
          itemList: []
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '仓库代码',
          dataIndex: 'storageCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '仓库名称',
          dataIndex: 'storageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库位编号',
          dataIndex: 'storagePositionCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '期初库存数量',
          dataIndex: 'stockQuantity',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '流水账代码',
          dataIndex: 'flowId',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '不含税成本金额',
          dataIndex: 'costAmount',
          sorter: true,
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '不含税成本单价',
          dataIndex: 'costPrice',
          sorter: true,
          filter: true,
          filterType: 'number'
        }
      ];
    },
    async getStorage() {
      const res = await getStroageList();
      this.topFilterList.find(item => item.fieldName === 'STORAGE_CODE').itemList = res.data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE }));
    },
    changeHandler(val) {
      this.fetchParams = { ...val };
    },
    rowSelectHandle(rows) {
      if (!rows.length) return;
      this.selectedRow = rows[0];
    },
    // 主页面刷新
    refreshHandle() {
      this.fetchParams = { ...this.fetchParams };
    },

    // 适配 BaseTable 组件
    collapseHandle() {
      this.$nextTick(this.BaseTable.EXECUTE_RESET_HEIGHT);
    }
  }
};
</script>

<style lang="less" scoped></style>
